1 module dlangui_bearlibterminal.drawbuf; 2 3 import BearLibTerminal: BT = terminal; 4 import dlangui; 5 6 class BearLibDrawBuf : ConsoleDrawBuf 7 { 8 private int _width; 9 private int _height; 10 11 this(int w, int h) 12 { 13 _width = w; 14 _height = h; 15 } 16 17 void drawCharWithEffects(int x, int y, dchar ch, bool underscore, uint color) 18 { 19 BT.color(color.toColor); 20 BT.put(x, y, ch); 21 22 if(underscore) 23 { 24 BT.layer(1); 25 BT.put(x, y, '_'); 26 BT.layer(0); 27 } 28 } 29 30 override: 31 32 @property int width() { return _width; } 33 @property int height() { return _height; } 34 35 /// reserved for hardware-accelerated drawing - begins drawing batch 36 void beforeDrawing() 37 { 38 assert(false, __FUNCTION__~" isn't implemented"); 39 } 40 41 /// reserved for hardware-accelerated drawing - ends drawing batch 42 void afterDrawing() 43 { 44 assert(false, __FUNCTION__~" isn't implemented"); 45 } 46 47 void drawChar(int x, int y, dchar ch, uint color, uint bgcolor) 48 { 49 BT.color(color.toColor); 50 BT.bkcolor(bgcolor.toColor); 51 52 BT.put(x, y, ch); 53 } 54 55 void resize(int _width, int _height) 56 { 57 if(width == _width && width == _height) 58 return; 59 else 60 assert(false, __FUNCTION__~": resizing isn't implemented"); 61 62 //~ _dx = width; 63 //~ _dy = height; 64 65 //~ resetClipping(); 66 } 67 68 void fill(uint color) 69 { 70 assert(false, __FUNCTION__~" isn't implemented"); 71 } 72 73 /// fill rectangle with solid color (clipping is applied) 74 void fillRect(Rect rc, uint color) 75 { 76 uint alpha = color >> 24; 77 78 if (alpha >= 128) 79 return; // transparent 80 81 BT.bkcolor(color); 82 BT.clear_area(rc.left, rc.top, rc.width, rc.height); 83 } 84 85 void drawPixel(int x, int y, uint color) 86 { 87 assert(false, __FUNCTION__~" isn't implemented"); 88 } 89 90 void drawGlyph(int x, int y, Glyph* glyph, uint color) 91 { 92 assert(false, __FUNCTION__~" isn't implemented"); 93 } 94 95 void drawFragment(int x, int y, DrawBuf src, Rect srcrect) 96 { 97 assert(false, __FUNCTION__~" isn't implemented"); 98 } 99 100 void drawRescaled(Rect dstrect, DrawBuf src, Rect srcrect) 101 { 102 assert(false, __FUNCTION__~" isn't implemented"); 103 } 104 105 void fillGradientRect(Rect rc, uint color1, uint color2, uint color3, uint color4) 106 { 107 //~ fillRect(rc, color1); 108 assert(false, __FUNCTION__~" isn't implemented"); 109 } 110 111 @property int bpp() { return 4; } 112 113 void clear() { 114 resetClipping(); 115 } 116 } 117 118 package: 119 120 static import BearLibTerminal; 121 122 BearLibTerminal.color_t toColor(uint fromColor) pure 123 { 124 return fromColor ^ 0xFF_00_00_00; 125 }